﻿using GalaSoft.MvvmLight;
using System;
using System.Windows;
using TransControlSystem.ViewModel.Common;

namespace TransControlSystem.Model
{
    public class AlgorithmListModel : ObservableObject
    {
        #region 数据库PriorityConfig表中字段
        //主键
        private int _Id;
        /// <summary>
        /// 主键
        /// </summary>
        public int Id
        {
            get { return _Id; }
            set
            {
                _Id = value;
                RaisePropertyChanged(() => Id);
            }
        }

        //优先级
        private string _Priority;
        /// <summary>
        /// 优先级
        /// </summary>
        public string Priority
        {
            get
            {
                return _Priority;
            }
            set
            {
                _Priority = value;
                RaisePropertyChanged(() => Priority);
            }
        }
        //优先级序号
        private int _PriorityNo;
        /// <summary>
        /// 优先级序号 
        /// </summary>
        public int PriorityNo
        {
            get
            {
                return _PriorityNo;
            }
            set
            {
                _PriorityNo = value;
                RaisePropertyChanged(() => PriorityNo);
            }
        }
        //优先级数字排列序号 对应PriorityNo
        private int _PriorityArrangementNumber;
        /// <summary>
        /// 优先级数字排列序号 对应PriorityNo
        /// </summary>
        public int PriorityArrangementNumber
        {
            get
            {
                return _PriorityArrangementNumber;
            }
            set
            {
                _PriorityArrangementNumber = value;
                RaisePropertyChanged(() => PriorityArrangementNumber);
            }
        }
        #endregion 数据库PriorityConfig表中字段
        #region 数据库TagInfo表中字段
        //设备名称
        private string _EquipmentName;
        /// <summary>
        /// 设备名称
        /// </summary>
        public string EquipmentName
        {
            get { return _EquipmentName; }
            set
            {
                _EquipmentName = value;
                RaisePropertyChanged(() => EquipmentName);
            }
        }
        /// <summary>
        /// 排序序号
        /// </summary>
        private Int64 _OrderNo;
        /// <summary>
        /// 排序序号
        /// </summary>
        public Int64 OrderNo
        {
            get { return _OrderNo; }
            set
            {
                _OrderNo = value;
                RaisePropertyChanged(() => OrderNo);
            }
        }
        //程序块名称
        private string _TagDesc;
        /// <summary>
        /// 程序块名称
        /// </summary>
        public string TagDesc
        {
            get { return _TagDesc; }
            set
            {
                _TagDesc = value;
                RaisePropertyChanged(() => TagDesc);
            }
        }
        //程序块地址
        private string _Address;
        /// <summary>
        /// 程序块地址
        /// </summary>
        public string Address
        {
            get { return _Address; }
            set
            {
                _Address = value;
                RaisePropertyChanged(() => Address);
            }
        }
        //程序块值数据类型
        private string _ValueType;
        /// <summary>
        /// 程序块值数据类型
        /// </summary>
        public string ValueType
        {
            get { return _ValueType; }
            set
            {
                _ValueType = value;
                RaisePropertyChanged(() => ValueType);
            }
        }
        //程序块值
        private string _Value;
        /// <summary>
        /// 程序块值
        /// </summary>
        public string Value
        {
            get { return _Value; }
            set
            {
                _Value = value;
                RaisePropertyChanged(() => Value);
            }
        }

        //点位
        private string _Point;
        /// <summary>
        /// 点位
        /// </summary>
        public string Point
        {
            get { return _Point; }
            set
            {
                _Point = value;
                RaisePropertyChanged(() => Point);
            }
        }
        //读写属性：1=可读，2=可读可写
        private bool _ReadOrWrite;
        /// <summary>
        /// 读写属性：1=可读，2=可读可写
        /// </summary>
        public bool ReadOrWrite
        {
            get { return _ReadOrWrite; }
            set
            {
                _ReadOrWrite = value;
                RaisePropertyChanged(() => ReadOrWrite);
            }
        }
        //程序块的说明
        private string _Remark;
        /// <summary>
        /// 程序块的说明
        /// </summary>
        public string Remark
        {
            get
            {
                return _Remark;
            }
            set
            {
                _Remark = value;
                RaisePropertyChanged(() => Remark);
            }
        }
        //是否可用：true是启用，false是不启用
        private bool _IsEnable;
        /// <summary>
        /// 是否可用：true是启用，false是不启用
        /// </summary>
        public bool IsEnable
        {
            get { return _IsEnable; }
            set
            {
                _IsEnable = value;
                RaisePropertyChanged(() => IsEnable);
            }
        }
        //类别：1是普通程序块，2是任务程序块，3是加料车任务反馈程序块
        private int _Type;
        /// <summary>
        /// 类别：1是普通程序块，2是任务程序块，3是加料车任务反馈程序块
        /// </summary>
        public int Type
        {
            get { return _Type; }
            set
            {
                _Type = value;
                RaisePropertyChanged(() => Type);
            }
        }
        #endregion 数据库TagInfo表中字段


        /// <summary>
        /// MainWindow 任务列表显示任务状态 是否执行中 显隐完成按钮
        /// </summary>
        public Visibility IsTheTaskInProgressVisibility
        {

            get
            {
                if (_Status == "执行中")
                {
                    return Visibility.Visible;
                }
                else
                {
                    return Visibility.Hidden;
                }
            }
        }
        /// <summary>
        /// 显隐删除
        /// </summary>
        public Visibility FunctionSimulationVisibility
        {
            get
            {
                if (LogTool.CurrentUser.Role == "system")
                {
                    return Visibility.Visible;
                }
                else
                {
                    return Visibility.Hidden;
                }
            }
        }

        /// <summary>
        /// 是否正在执行 用于逻辑判断
        /// </summary>
        public bool IsTheTaskInProgress
        {
            get
            {
                return OrderNo == 1;
            }
        }


        /// <summary>
        /// 是否其他正在执行 用于逻辑判断
        /// </summary>
        public bool IsTheTaskNotPerformed
        {
            get
            {
                return OrderNo != 1;
            }
        }

        /// <summary>
        /// 是否其他正在执行 用于逻辑判断
        /// </summary>
        public Visibility IsTheTaskNotPerformedVisibility
        {

            get
            {
                if (Status == "等待")
                {
                    return Visibility.Visible;
                }
                else
                {
                    return Visibility.Hidden;
                }
            }
        }

        #region 触发生成任务的程序块属性
        //首要触发创建任务程序块描述
        private string _FirstTriggersBuildTaskTagDesc;
        /// <summary>
        /// 首要触发创建任务程序块描述
        /// </summary>
        public string FirstTriggersBuildTaskTagDesc
        {
            get { return _FirstTriggersBuildTaskTagDesc; }
            set
            {
                _FirstTriggersBuildTaskTagDesc = value;
                RaisePropertyChanged(() => FirstTriggersBuildTaskTagDesc);
            }
        }
        //首要触发创建任务程序块地址
        private string _FirstTriggersBuildTaskAddress;
        /// <summary>
        /// 首要触发创建任务程序块地址
        /// </summary>
        public string FirstTriggersBuildTaskAddress
        {
            get { return _FirstTriggersBuildTaskAddress; }
            set
            {
                _FirstTriggersBuildTaskAddress = value;
                RaisePropertyChanged(() => FirstTriggersBuildTaskAddress);
            }
        }
        //首要触发创建任务程序块值类型
        private string _FirstTriggersBuildTaskValueType;
        /// <summary>
        /// 首要触发创建任务程序块值类型
        /// </summary>
        public string FirstTriggersBuildTaskValueType
        {
            get { return _FirstTriggersBuildTaskValueType; }
            set
            {
                _FirstTriggersBuildTaskValueType = value;
                RaisePropertyChanged(() => FirstTriggersBuildTaskValueType);
            }
        }

        //首要触发创建任务程序块值
        private string _FirstTriggersBuildTaskValue;
        /// <summary>
        /// 首要触发创建任务程序块值
        /// </summary>
        public string FirstTriggersBuildTaskValue
        {
            get { return _FirstTriggersBuildTaskValue; }
            set
            {
                _FirstTriggersBuildTaskValue = value;
                RaisePropertyChanged(() => FirstTriggersBuildTaskValue);
            }
        }

        //首要触发创建任务点位
        private string _FirstTriggersBuildTaskPoint;
        /// <summary>
        /// 首要触发创建任务点位
        /// </summary>
        public string FirstTriggersBuildTaskPoint
        {
            get { return _FirstTriggersBuildTaskPoint; }
            set
            {
                _FirstTriggersBuildTaskPoint = value;
                RaisePropertyChanged(() => _FirstTriggersBuildTaskPoint);
            }
        }
        //次要触发创建任务程序块描述
        private string _SecondaryTriggersBuildTaskTagDesc;
        /// <summary>
        /// 次要触发创建任务程序块描述
        /// </summary>
        public string SecondaryTriggersBuildTaskTagDesc
        {
            get { return _SecondaryTriggersBuildTaskTagDesc; }
            set
            {
                _SecondaryTriggersBuildTaskTagDesc = value;
                RaisePropertyChanged(() => SecondaryTriggersBuildTaskTagDesc);
            }
        }
        //次要触发创建任务程序块地址
        private string _SecondaryTriggersBuildTaskAddress;
        /// <summary>
        /// 次要触发创建任务程序块地址
        /// </summary>
        public string SecondaryTriggersBuildTaskAddress
        {
            get { return _SecondaryTriggersBuildTaskAddress; }
            set
            {
                _SecondaryTriggersBuildTaskAddress = value;
                RaisePropertyChanged(() => SecondaryTriggersBuildTaskAddress);
            }
        }
        //次要触发创建任务程序块值类型
        private string _SecondaryTriggersBuildTaskValueType;
        /// <summary>
        /// 次要触发创建任务程序块值类型
        /// </summary>
        public string SecondaryTriggersBuildTaskValueType
        {
            get { return _SecondaryTriggersBuildTaskValueType; }
            set
            {
                _SecondaryTriggersBuildTaskValueType = value;
                RaisePropertyChanged(() => SecondaryTriggersBuildTaskValueType);
            }
        }

        //次要触发创建任务程序块值
        private string _SecondaryTriggersBuildTaskValue;
        /// <summary>
        /// 次要触发创建任务程序块值
        /// </summary>
        public string SecondaryTriggersBuildTaskValue
        {
            get { return _SecondaryTriggersBuildTaskValue; }
            set
            {
                _SecondaryTriggersBuildTaskValue = value;
                RaisePropertyChanged(() => SecondaryTriggersBuildTaskValue);
            }
        }
        //次要触发创建任务点位
        private string _SecondaryTriggersBuildTaskPoint;
        /// <summary>
        /// 次要触发创建任务点位
        /// </summary>
        public string SecondaryTriggersBuildTaskPoint
        {
            get { return _SecondaryTriggersBuildTaskPoint; }
            set
            {
                _SecondaryTriggersBuildTaskPoint = value;
                RaisePropertyChanged(() => SecondaryTriggersBuildTaskPoint);
            }
        }
        //触发的任务的程序块描述
        private string _TriggeredTaskTagDesc;
        /// <summary>
        /// 触发的任务的程序块描述
        /// </summary>
        public string TriggeredTaskTagDesc
        {
            get { return _TriggeredTaskTagDesc; }
            set
            {
                _TriggeredTaskTagDesc = value;
                RaisePropertyChanged(() => TriggeredTaskTagDesc);
            }
        }
        //触发的任务的程序块地址
        private string _TriggeredTaskAddress;
        /// <summary>
        /// 触发的任务的程序块地址
        /// </summary>
        public string TriggeredTaskAddress
        {
            get { return _TriggeredTaskAddress; }
            set
            {
                _TriggeredTaskAddress = value;
                RaisePropertyChanged(() => TriggeredTaskAddress);
            }
        }

        //触发的任务的程序块值类型
        private string _TriggeredTaskValueType;
        /// <summary>
        /// 触发的任务的程序块值类型
        /// </summary>
        public string TriggeredTaskValueType
        {
            get { return _TriggeredTaskValueType; }
            set
            {
                _TriggeredTaskValueType = value;
                RaisePropertyChanged(() => TriggeredTaskValueType);
            }
        }


        //触发的任务的程序块值
        private string _TriggeredTaskValue;
        /// <summary>
        /// 触发的任务的程序块值
        /// </summary>
        public string TriggeredTaskValue
        {
            get { return _TriggeredTaskValue; }
            set
            {
                _TriggeredTaskValue = value;
                RaisePropertyChanged(() => TriggeredTaskValue);
            }
        }

        /// <summary>
        /// 监控第一程序块值
        /// </summary>
        public bool TagIsOn
        {
            get
            {
                if (ValueType == "Bool" && Value == "True")
                {
                    return true;
                }
                else if (ValueType == "Bool" && Value == "False")
                {
                    return false;
                }
                return false;
            }
        }
        /// <summary>
        /// 监控触发第一程序块值
        /// </summary>
        public bool FirstTriggersTagIsOn
        {
            get
            {
                if ((FirstTriggersBuildTaskValueType == "Bool" && FirstTriggersBuildTaskValue == "True") || (FirstTriggersBuildTaskValueType == "Dint" && FirstTriggersBuildTaskValue == "0"))
                {
                    return true;
                }
                else if ((FirstTriggersBuildTaskValueType == "Bool" && FirstTriggersBuildTaskValue == "False") || (FirstTriggersBuildTaskValueType == "Dint" && FirstTriggersBuildTaskValue != "0"))
                {
                    return false;
                }
                return false;
            }
        }

        /// <summary>
        /// 监控触发第二程序块值
        /// </summary>
        public bool SecondaryTriggersTagIsOn
        {
            get
            {
                if ((SecondaryTriggersBuildTaskValueType == "Bool" && SecondaryTriggersBuildTaskValue == "True") || (SecondaryTriggersBuildTaskValueType == "Dint" && SecondaryTriggersBuildTaskValue == "0"))
                {
                    return true;
                }
                else if ((SecondaryTriggersBuildTaskValueType == "Bool" && SecondaryTriggersBuildTaskValue == "False") || (SecondaryTriggersBuildTaskValueType == "Dint" && SecondaryTriggersBuildTaskValue != "0"))
                {
                    return false;
                }
                return false;
            }
        }
        #endregion 触发生成任务的程序块属性

        #region 数据库中TaskInfo表中字段
        //任务描述
        private string _TaskDesc;
        /// <summary>
        /// 任务描述
        /// </summary>
        public string TaskDesc
        {
            get { return _TaskDesc; }
            set
            {
                _TaskDesc = value;
                RaisePropertyChanged(() => TaskDesc);
            }
        }
        //任务创建时间
        private DateTime _CreateTime;
        /// <summary>
        /// 任务创建时间
        /// </summary>
        public DateTime CreateTime
        {
            get { return _CreateTime; }
            set
            {
                _CreateTime = value;
                RaisePropertyChanged(() => CreateTime);
            }
        }
        //任务开始时间
        private DateTime _StartTime;
        /// <summary>
        /// 任务开始时间
        /// </summary>
        public DateTime StartTime
        {
            get { return _StartTime; }
            set
            {
                _StartTime = value;
                RaisePropertyChanged(() => StartTime);
            }
        }
        //任务结束时间
        private DateTime _EndTime;
        /// <summary>
        /// 任务结束时间
        /// </summary>
        public DateTime EndTime
        {
            get { return _EndTime; }
            set
            {
                _EndTime = value;
                RaisePropertyChanged(() => EndTime);
            }
        }
        //起点
        private string _StartPoint;
        /// <summary>
        /// 起点
        /// </summary>
        public string StartPoint
        {
            get { return _StartPoint; }
            set
            {
                _StartPoint = value;
                RaisePropertyChanged(() => StartPoint);
            }
        }
        //终点
        private string _EndPoint;
        /// <summary>
        /// 终点
        /// </summary>
        public string EndPoint
        {
            get { return _EndPoint; }
            set
            {
                _EndPoint = value;
                RaisePropertyChanged(() => EndPoint);
            }
        }
        //任务状态 1：等待，2：执行中，3：已完成
        private string _Status;
        /// <summary>
        /// 任务状态 1：等待，2：执行中，3：已完成
        /// </summary>
        public string Status
        {
            get { return _Status; }
            set
            {
                _Status = value;
                RaisePropertyChanged(() => Status);
            }
        }
        //任务排序 只有等待中的任务才有排序
        private int _DataOrderNo;
        /// <summary>
        /// 任务排序 只有等待中的任务才有排序
        /// </summary>
        public int DataOrderNo
        {
            get { return _DataOrderNo; }
            set
            {
                _DataOrderNo = value;
                RaisePropertyChanged(() => DataOrderNo);
            }
        }
        //是否删除 1=删除
        private int _IsDelete;
        /// <summary>
        /// 是否删除 1=删除
        /// </summary>
        public int IsDelete
        {
            get { return _IsDelete; }
            set
            {
                _IsDelete = value;
                RaisePropertyChanged(() => IsDelete);
            }
        }
        #endregion 数据库中TaskInfo表中字段

        #region 用于主界面格式化显示时间使用
        /// <summary>
        /// 创建时间格式化显示
        /// </summary>
        public string CreateTimeText
        {
            get
            {
                if (CreateTime != null && CreateTime.Ticks != 0)
                {
                    return CreateTime.Year + "年" + CreateTime.Month.ToString("00") + "月" + CreateTime.Day.ToString("00") + "日" + " " + CreateTime.Hour.ToString("00") + ":" + CreateTime.Minute.ToString("00") + ":" + CreateTime.Second.ToString("00");
                }
                return "";
            }
        }
        /// <summary>
        /// 开始时间格式化显示
        /// </summary>
        public string StartTimeText
        {
            get
            {
                if (StartTime != null && StartTime.Ticks != 0)
                {
                    return StartTime.Year + "年" + StartTime.Month.ToString("00") + "月" + StartTime.Day.ToString("00") + "日" + " " + StartTime.Hour.ToString("00") + ":" + StartTime.Minute.ToString("00") + ":" + StartTime.Second.ToString("00");
                }
                return "";
            }
        }
        /// <summary>
        /// 结束时间格式化显示
        /// </summary>
        public string EndTimeText
        {
            get
            {
                if (EndTime != null && EndTime.Ticks != 0)
                {
                    return EndTime.Year + "年" + EndTime.Month.ToString("00") + "月" + EndTime.Day.ToString("00") + "日" + " " + EndTime.Hour.ToString("00") + ":" + EndTime.Minute.ToString("00") + ":" + EndTime.Second.ToString("00");
                }
                return "";
            }
        }
        #endregion 用于主界面格式化显示时间使用
        /// <summary>
        /// 任务查询页面显示删除状态使用
        /// </summary>
        public string IsDeleteText
        {
            get
            {
                if (IsDelete == 1)
                {
                    return "已删除";
                }
                return "正常";
            }
        }
    }
}
